//
//  FindPasswordViewController.m
//  project
//
//  Created by 张亚林 on 2017/10/25.
//  Copyright © 2017年 Macmini. All rights reserved.
//

#import "FindPasswordViewController.h"

#import "SetnewPasswordViewController.h"
#import "ZWTools.h"
#import "MBProgressHUD+KR.h"
#import "STValidateCode.h"

@interface FindPasswordViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTF;

@property (weak, nonatomic) IBOutlet UITextField *msgCodeTF;

@end

@implementation FindPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.phoneTF.text  = @"13111111111";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)clickMsgCode:(id)sender {
    
    ZWTools *tools = [ZWTools sharedManager];
    [tools getPhoneCodeFromNetWorkingID:self.phoneTF.text sucessBlock:^(id jsonResponse) {
        
        
        [STValidateCode timeCuntDown:sender];
        
    } Error:^(id jsonResponse) {
        
    }];
}


- (IBAction)clickContinueBtn:(id)sender {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter[@"phone"] = self.phoneTF.text;
    requestParameter[@"msgCode"] = self.msgCodeTF.text;
    
    ZWTools *tools = [ZWTools sharedManager];
    [tools doFindUser:requestParameter sucessBlock:^(id jsonResponse) {
        
        NSString *result = [jsonResponse objectForKey:@"code"];
        NSLog(@"%@", result);
        if ([result isEqualToString:@"0000"]) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                SetnewPasswordViewController *setNPWVC = [[SetnewPasswordViewController alloc] init];
                setNPWVC.phone = self.phoneTF.text;
                [self.navigationController pushViewController:setNPWVC animated:YES];
                
            });
        } else if ([result isEqualToString:@"100"]) {
            
            [MBProgressHUD showSuccess:@"操作失败"];
        }
        
    } Error:^(id jsonResponse) {
        
    }];
}

@end
